#pragma once

#include <GL/glew.h>
#include <QGLWidget>
#include <QTimer.h>

#include "../Core/DCoordinates3.h"
#include "../Core/TriangulatedMeshes3.h"
#include "../Core/Materials.h"

namespace cagd
{
    class GLWidget: public QGLWidget
    {
        // ever class that provides signals and slots mechanism needs to define the
        // Q_OBJECT macro
        Q_OBJECT

    protected:
        // parameters of the perspective projection matrix
        GLfloat _aspect, _fovy, _z_near, _z_far;

        // parameters of the modelview matrix
        DCoordinate3 _eye, _center, _up;

        // geometry
        TriangulatedMesh3 _mouse;

        // transformation parameters
        GLdouble _scale;
        GLdouble _trans_x, _trans_y, _trans_z;
        GLdouble _angle_x, _angle_y, _angle_z;

        GLuint _random_material;

        QTimer *_timer;
        GLfloat _angle;

    public:
        // default/special constructor
        GLWidget(QWidget *parent = 0, const QGLFormat &format = QGL::Rgba | QGL::DepthBuffer | QGL::DoubleBuffer);

        // inherited methods that must be redeclared/redefined
        void initializeGL();
        void paintGL();
        void resizeGL(int w, int h);

        // desctructor
        ~GLWidget();

    public slots:

        // public event handlers
        void set_angle_x(int value);
        void set_angle_y(int value);
        void set_angle_z(int value);

        void set_trans_x(double value);
        void set_trans_y(double value);
        void set_trans_z(double value);

        void set_zoom_factor(double value);

        void reset_to_original_view();

        void load_mouse();

        void load_elephant();

        void randomizeMat();

        void animate();
    };
}
